#include "MirrorMaterial.cuh"

using namespace OBR;

/**
 * @brief generate new ray info and add to the next ray, then return beta of the ray
 *
 * @param prd
 * @param instance_id
 * @return beta
 */
static __forceinline__ __device__ Spectrum rayGeneration(SamplePRD *prd, float *pdf)
{
    prd->inter.wi = prd->inter.spawnRay(reflect(prd->inter.wo.d, prd->inter.n));

#ifdef DEBUG_SHADER
    if (prd->log)
    {
        printf("in: ");
        print_float3(prd->inter.wi.d);
        printf("\n");

        printf("normal: ");
        print_float3(prd->inter.n);
        printf("\n");

        printf("out: ");
        print_float3(prd->inter.wo.d);
        printf("\n");
    }
#endif

    *pdf = 1.0f;
    return Spectrum(1.0f);
}

extern "C" __device__ Spectrum __direct_callable__mirror_material(SamplePRD *prd, float *pdf,
                                                                  float u0, float u1,
                                                                  MaterialCallMode mode)
{
    // this material contains no sbt data
    if (mode == MaterialCallMode::SAMPLE_FR)
    {
        return rayGeneration(prd, pdf);
    }
    else if (mode == MaterialCallMode::CALC_FR_PDF)
    {
        *pdf = 0;
        return Spectrum(0.0f);
    }
    return Spectrum(0.0f);
}